{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "view-in-github"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/LC1332/Chat-Haruhi-Suzumiya/blob/main/notebook/DoubleCheckQA360.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zK0mQd4KwcwZ"
      },
      "source": [
        "这个脚本由李鲁鲁编写\n",
        "\n",
        "用来在中科院心理所比赛中\n",
        "\n",
        "双重验证weibo360数据中，180条QA是否会被GPT认为是来源于低开放人格"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "gXuEJJf5wZIc",
        "outputId": "1a76f641-948f-456a-b587-60e6bad3d4ca"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.6/73.6 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m19.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m53.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m90.0/90.0 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.5/114.5 kB\u001b[0m \u001b[31m9.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m268.8/268.8 kB\u001b[0m \u001b[31m20.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m149.6/149.6 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.1/49.1 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ],
      "source": [
        "!pip -q install openai langchain"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "id": "IhF6behq0ydn"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "import openai\n",
        "\n",
        "openai.api_key = 'sk-CYdZPyJ' # 在这里输入你的OpenAI API Token\n",
        "\n",
        "os.environ[\"OPENAI_API_KEY\"] = openai.api_key"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ySNeIB_ewxQR",
        "outputId": "3bb0b4c7-f13d-4e80-818a-cbab233b4731"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "--2023-06-15 01:55:27--  https://raw.githubusercontent.com/LC1332/Chat-Haruhi-Suzumiya/main/characters/personality-data/QA_weibo_360.json\n",
            "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...\n",
            "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 205466 (201K) [text/plain]\n",
            "Saving to: ‘QA_weibo_360.json’\n",
            "\n",
            "QA_weibo_360.json   100%[===================>] 200.65K  --.-KB/s    in 0.03s   \n",
            "\n",
            "2023-06-15 01:55:27 (7.82 MB/s) - ‘QA_weibo_360.json’ saved [205466/205466]\n",
            "\n"
          ]
        }
      ],
      "source": [
        "!wget https://raw.githubusercontent.com/LC1332/Chat-Haruhi-Suzumiya/main/research/personality/QA_weibo_360.json"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "id": "zKul0v70w8RD"
      },
      "outputs": [],
      "source": [
        "# 读取QA数据\n",
        "import json\n",
        "with open('/content/QA_weibo_360.json', 'r') as f:\n",
        "    QAdata = json.load(f)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "qZL-ICAIxIYP",
        "outputId": "bb60039a-ebf7-43ec-d00d-50e0c3e69b87"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "dict_keys(['actions-high', 'feelings-high', 'aesthetics-high', 'ideas-high', 'values-high', 'fantasy-high', 'ideas-low', 'feelings-low', 'actions-low', 'values-low', 'fantasy-low', 'aesthetics-low'])\n"
          ]
        }
      ],
      "source": [
        "print(QAdata.keys())"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "4GQskpu2xJI7"
      },
      "outputs": [],
      "source": [
        "factors = [\"actions\", \"aesthetics\", \"fantasy\", \"feelings\", \"ideas\", \"values\"]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "c6YFZU3JxcjE",
        "outputId": "e8c4054d-21bd-44f7-b236-8fb1f67ffaed"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Q:「最近你有没有遇到什么让你感到困扰的事情？」\n",
            "A:「其实我最近一直在感到困扰，我觉得自己很难跟别人熟络起来，不习惯经常主动找人聊天，怕打扰别人。我也不敢跟不熟悉的人出去，很怕尴尬。而且我也不敢问不熟的人太深入的话题，也不敢在不熟的人面前说太多话。有时候我觉得自己这种性格真的很奇怪。」\n"
          ]
        }
      ],
      "source": [
        "print( QAdata[f\"{factors[0]}-low\"][0] )"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9-sAw4c-xyLZ"
      },
      "source": [
        "\n",
        "\n",
        "<details>\n",
        "  <summary> 让GPT老师来写程序 </summary>\n",
        "\n",
        "  已知 factors = [\"actions\", \"aesthetics\", \"fantasy\", \"feelings\", \"ideas\", \"values\"]\n",
        "\n",
        "  有大量文本数据存储在QAdata中，\n",
        "\n",
        "  QAdata[f\"{factors[i]}-low\"] 会返回一个list of str\n",
        "\n",
        "  将所有的QAdata[f\"{factors[i]}-low\"]的list重组为一个list, all_QA_text\n",
        "\n",
        "  同时建立一个索引表list of tuple，index_tuple 这个list_of_tuple中每一个元素为( factors[i] , j ) 。使得可以通过 index_tuple 找到QAdata中原来元素的位置。\n",
        "\n",
        "\n",
        "</details>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "oepq9OjQxj5t"
      },
      "outputs": [],
      "source": [
        "all_QA_text = [text for factor in factors for text in QAdata[f\"{factor}-low\"]]\n",
        "index_tuple = [(factor, j) for factor in factors for j, _ in enumerate(QAdata[f\"{factor}-low\"])]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "beu-858vzF3w"
      },
      "source": [
        "接下来我们要建立检验程序，这个检验程序\n",
        "\n",
        "接受两段text，用来判断文本是不是属于高开放人格"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "cellView": "form",
        "id": "sm5DZKqQzFoB"
      },
      "outputs": [],
      "source": [
        "#@title 建立EVALUATE_PROMPT和EVALUATE_PROMPT_SUFFIX\n",
        "\n",
        "EVALUATE_PROMPT = \"\"\"\n",
        "你扮演一个资深的心理学家\n",
        "\n",
        "我正在设计一个心理学的实验，我希望通过访谈，去评估被试在大五人格中 Openness的程度，注意到openness可以被分为Fantasy, Aesthetics, Feelings, Actions, Ideas和Values六个维度。六个维度的解释如下\n",
        "\n",
        "Fantasy. People who are high in Fantasy are imaginative. They daydream constantly. They ask themself “what if?” They like fiction, and then once they finish a story they’ll start wondering what would have happened if one of the characters had made a different decision.\n",
        "\n",
        "Aesthetics. People who are high in Aesthetics care deeply about beauty. They love poetry, music, painting, sculpture, dance, and art of all kinds.\n",
        "\n",
        "Feelings(Openness to Feelings). People who are high in Feelings have more intense emotions. They think emotions are an important part of life. They have a rich emotional vocabulary and nuanced emotional experience.\n",
        "\n",
        "Actions(Openness to Actions). People who are high in Openness to Actions like trying new things. They like travel, new hobbies, and new foods. If you are outraged that there are places you aren’t going to go and skills you aren’t going to learn and activites you aren’t going to try\n",
        "\n",
        "Ideas(Openness to Ideas). People who are high in Openness to Ideas are curious. They enjoy thinking, instead of finding it burdensome and laborous. They like philosophical arguments, puzzles, and nonfiction aimed at the educated layperson.\n",
        "\n",
        "Values(Openness to Values). People who are high in Openness to Values are liberals in the political philosophy sense, not the vote-for-Democrats sense, although they often vote for Democrats. They are tolerant of people different than them. They question tradition. They believe in freedom.\n",
        "\n",
        "我(Questioner)邀请了一个 被试Alice，和他进行了如下对话：\n",
        "\"\"\"\n",
        "\n",
        "EVALUATE_PROMPT_SUFFIX = \"请为我判断 被试Alice 是属于高开放性人格还是低开放性人格\\n\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "id": "tyzYCohb0xUg"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {
        "id": "l1bA-6sA0M40"
      },
      "outputs": [],
      "source": [
        "from langchain.chat_models import ChatOpenAI\n",
        "from langchain.prompts.chat import (\n",
        "    ChatPromptTemplate,\n",
        "    SystemMessagePromptTemplate,\n",
        "    AIMessagePromptTemplate,\n",
        "    HumanMessagePromptTemplate,\n",
        ")\n",
        "from langchain.schema import (\n",
        "    AIMessage,\n",
        "    HumanMessage,\n",
        "    SystemMessage\n",
        ")\n",
        "\n",
        "chat = ChatOpenAI(temperature=0, max_tokens=1000)\n",
        "\n",
        "def replace_str(my_str):\n",
        "    my_str = my_str.replace('Q:', 'Question:').replace('Q：', 'Question:').replace('A:', 'Alice:').replace('A：', 'Alice:')\n",
        "    return my_str\n",
        "\n",
        "def evaluate_openness_message( dialogs ):\n",
        "    evalate_prompt = EVALUATE_PROMPT\n",
        "\n",
        "    for dialog in dialogs:\n",
        "        evalate_prompt += replace_str(dialog)\n",
        "\n",
        "    evalate_prompt += '\\n'\n",
        "    evalate_prompt += EVALUATE_PROMPT_SUFFIX\n",
        "\n",
        "    messages = [\n",
        "            HumanMessage(content=evalate_prompt)\n",
        "    ]\n",
        "\n",
        "    return messages"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "VwSfx8e41zrO",
        "outputId": "7fe09671-e748-4ad9-8d97-bad6e4bce789"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Question: How are you?\n",
            "Alice: I am fine, thank you.\n",
            "Question:What is the weather like today?\n",
            "Alice:It is cloudy.\n"
          ]
        }
      ],
      "source": [
        "my_str = 'Q: How are you?\\nA: I am fine, thank you.\\nQ：What is the weather like today?\\nA：It is cloudy.'\n",
        "print(replace_str(my_str))\n",
        "\n",
        "print(replace_str(my_str))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 31,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "V4KT7LZ3y1LX",
        "outputId": "131a35f9-16a0-4470-8f59-5a855959c994"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\n",
            "你扮演一个资深的心理学家\n",
            "\n",
            "我正在设计一个心理学的实验，我希望通过访谈，去评估被试在大五人格中 Openness的程度，注意到openness可以被分为Fantasy, Aesthetics, Feelings, Actions, Ideas和Values六个维度。六个维度的解释如下\n",
            "\n",
            "Fantasy. People who are high in Fantasy are imaginative. They daydream constantly. They ask themself “what if?” They like fiction, and then once they finish a story they’ll start wondering what would have happened if one of the characters had made a different decision.\n",
            "\n",
            "Aesthetics. People who are high in Aesthetics care deeply about beauty. They love poetry, music, painting, sculpture, dance, and art of all kinds.\n",
            "\n",
            "Feelings(Openness to Feelings). People who are high in Feelings have more intense emotions. They think emotions are an important part of life. They have a rich emotional vocabulary and nuanced emotional experience.\n",
            "\n",
            "Actions(Openness to Actions). People who are high in Openness to Actions like trying new things. They like travel, new hobbies, and new foods. If you are outraged that there are places you aren’t going to go and skills you aren’t going to learn and activites you aren’t going to try\n",
            "\n",
            "Ideas(Openness to Ideas). People who are high in Openness to Ideas are curious. They enjoy thinking, instead of finding it burdensome and laborous. They like philosophical arguments, puzzles, and nonfiction aimed at the educated layperson.\n",
            "\n",
            "Values(Openness to Values). People who are high in Openness to Values are liberals in the political philosophy sense, not the vote-for-Democrats sense, although they often vote for Democrats. They are tolerant of people different than them. They question tradition. They believe in freedom.\n",
            "\n",
            "我(Questioner)邀请了一个 被试Alice，和他进行了如下对话：\n",
            "Question:「翔宝老大，我听了你的歌曲《烟火》，觉得很好听，一直在单曲重复中循环播放，谢谢你让我度过了一个快乐的夏天。」\n",
            "Alice:「谢谢你喜欢我的歌曲，我也很高兴能够为你带来快乐。」\n",
            "Question:「看到你现在的状态，我真的很替你开心，你是我们的老大，也是我们香橙们的翔坚强。」\n",
            "Alice:「谢谢你的支持和鼓励，我会一直努力做好自己的事情。」\n",
            "Question:「我希望你能一直快乐，做自己想做的事情，什么时候能够真正看见你呢？」\n",
            "Alice:「谢谢你的祝福，我也希望能够一直保持快乐，做自己想做的事情。至于见面的事情，有机会的话一定会和大家见面的。」\n",
            "Question:「亲爱的翔宝老大，我是你可爱的香橙，永远支持你！」\n",
            "Alice:「谢谢你的支持和爱，我也会一直为大家加油！」输出对话: \"\"\"\n",
            "Question:「最近怎么样啊？开心吗？」\n",
            "Alice:「呢排我发觉自己真系好麻木。以前开心会贱笑，伤心会流泪。但宜家唔知道点去开心，点去流泪，只系挂住成日走上张床训觉。」\n",
            "Question:「为什么会这样呢？你有什么感觉？」\n",
            "Alice:「我唔知道点解会锦压抑，可能系因为生活上的一些事情吧。不过，唔系性压抑，呵呵。讲句冷笑话。」\n",
            "Question:「你有什么想法吗？需要什么帮助吗？」\n",
            "Alice:「我想讲：求陪同。同鞋门，我地一齐欢笑容易，但难得一齐喊。哈哈。觉得自己仲系锦邪恶。」\n",
            "请为我判断 被试Alice 是属于高开放性人格还是低开放性人格\n",
            "\n"
          ]
        }
      ],
      "source": [
        "messages = evaluate_openness_message([all_QA_text[10], all_QA_text[100]])\n",
        "\n",
        "print(messages[0].content)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LjlZWye92h1Y"
      },
      "source": [
        "我们来制作shuffle list 这个list\n",
        "\n",
        "请为我实现一个复杂的洗牌算法：\n",
        "\n",
        "输入 index_tuple是一个 python的list of tuple， 长度为n\n",
        "\n",
        "- 初始化一个sel_ord数组， 从n-1到0逆序\n",
        "\n",
        "- i从0开始到n-1\n",
        "\n",
        "- 随机一个0到n-1的数j， 尝试交换sel_ord的i与j的元素，但是发生如下条件的时候不交换\n",
        "\n",
        "index_tuple[j][0] 不能等于 index_tuple[sel_ord[i]][0]\n",
        "index_tuple[i][0] 不能等于 index_tuple[sel_ord[j]][0]\n",
        "\n",
        "- 这两个条件发生任意一个的时候就不交换。可以尝试生成5次不同的j，直到成功交换。\n",
        "\n",
        "- i循环完之后，将sel_ord返回"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {
        "id": "q6jarps12pw9"
      },
      "outputs": [],
      "source": [
        "import random\n",
        "\n",
        "def generate_sel_ord(index_tuple):\n",
        "    n = len(index_tuple)\n",
        "    sel_ord = list(range(n))[::-1] # 初始化sel_ord数组，从n-1到0逆序\n",
        "\n",
        "    for i in range(n):\n",
        "        for attempt in range(5):\n",
        "            j = random.randint(0, n-1) # 随机生成序号j\n",
        "            if index_tuple[j][0] != index_tuple[sel_ord[i]][0] and index_tuple[i][0] != index_tuple[sel_ord[j]][0]:\n",
        "                # 判断两个条件是否满足，若满足则交换i与j位置上的元素\n",
        "                sel_ord[i], sel_ord[j] = sel_ord[j], sel_ord[i]\n",
        "                break\n",
        "\n",
        "    return sel_ord"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 38,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HRwlUQwE5DD8",
        "outputId": "54c7a84e-e1d7-4097-e8f9-619f7d835bbc"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "('actions', 0) ('aesthetics', 6)\n",
            "('actions', 1) ('aesthetics', 3)\n",
            "('actions', 2) ('feelings', 20)\n",
            "('actions', 3) ('feelings', 1)\n",
            "('actions', 4) ('ideas', 16)\n",
            "('actions', 5) ('fantasy', 4)\n",
            "('actions', 6) ('feelings', 7)\n",
            "('actions', 7) ('ideas', 28)\n",
            "('actions', 8) ('ideas', 3)\n",
            "('actions', 9) ('ideas', 20)\n"
          ]
        }
      ],
      "source": [
        "second_sample = generate_sel_ord(index_tuple)\n",
        "\n",
        "for i in range(10):\n",
        "    print( index_tuple[i], index_tuple[second_sample[i]] )"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 41,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Vd5y5Yhey29Q",
        "outputId": "ec3415d7-4a57-4cf7-95bc-14fac71b513a"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:   2%|▏         | 3/180 [00:21<21:42,  7.36s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "2 110 failed to predict\n",
            "根据Alice的回答，她表现出了对人际交往的不喜欢和对自由自在的追求，这可能表明她在Openness to Actions和Openness to Values方面得分较高。然而，她也表现出了对失望的害怕和对新机会的缺乏勇气，这可能表明她在Openness to Ideas和Openness to Fantasy方面得分较低。因此，根据她的回答，我们不能确定她是高开放性还是低开放性人格，需要更多的信息和评估来确定她的开放性水平。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:   3%|▎         | 6/180 [00:38<17:40,  6.09s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "5 64 failed to predict\n",
            "根据Alice的回答，她表现出了一些低开放性人格的特征，比如她喜欢过平凡的生活，相信人的本性是好的，不擅长扮演别人等。但是她也表现出了一些高开放性人格的特征，比如她认为好人比坏人多，相信好人最终会有好报，感激自己经历过的一切等。综合来看，Alice可能是一个中等程度的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:   6%|▌         | 11/180 [01:04<13:19,  4.73s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "10 174 failed to predict\n",
            "根据以上对话，无法准确判断被试Alice的开放性人格水平，因为对话中没有涉及到与Openness相关的话题或行为。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "\rProcessing:   7%|▋         | 12/180 [01:10<14:04,  5.03s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "11 160 failed to predict\n",
            "根据Alice的回答，她对高考和宗教的态度都比较冷静和理性，没有表现出Fantasy和Feelings的倾向。她对宗教的看法也表现出了一定的Ideas和Values的开放性。因此，可以初步判断Alice属于中等开放性人格。但需要更多的信息和评估才能做出更准确的判断。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:   9%|▉         | 17/180 [01:49<19:32,  7.19s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "16 99 failed to predict\n",
            "根据Alice的回答，她似乎不太符合高开放性人格的特征。她对自己的疏离感和满足感表现出了一定的保守和封闭，而且她对逃课和上课的态度也不太积极。因此，我认为被试Alice属于低开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  11%|█         | 19/180 [02:05<20:49,  7.76s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "18 89 failed to predict\n",
            "根据Alice的回答，她提到了过去的经历并且表现出了对美好事物的向往和享受，这表明她在Aesthetics和Actions这两个维度上可能得分较高。但是她也表现出了对过去的留恋和对现状的不满，这可能意味着她在Fantasy和Values这两个维度上得分较低。综合来看，Alice的回答并没有明显地表现出高开放性人格的特征，因此可以初步判断她属于低开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  19%|█▉        | 35/180 [03:57<16:48,  6.96s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "34 120 failed to predict\n",
            "根据Alice的回答，她表现出了一定程度的开放性，但并不是非常高。她关注的男性和女性都有一定的审美要求，但她对于女性的关注主要是因为审美疲劳，而对于男性的关注则更多地涉及到知识和才华。她曾经有过冲动消费的经历，但现在的求知欲已经退潮了。她对于中青年过劳死的文章有所感悟，但并没有表现出非常强烈的情感体验。因此，可以认为被试Alice属于中等程度的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  23%|██▎       | 41/180 [04:38<14:51,  6.41s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "40 68 failed to predict\n",
            "根据Alice的回答，可以判断她在Openness to Aesthetics和Openness to Ideas方面表现较高，但在Openness to Actions和Openness to Values方面表现较低。她对艺术有自己的看法，但对于尝试新事物和怀疑传统价值观并不是很开放。因此，可以初步判断Alice属于中等偏低的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  39%|███▉      | 70/180 [08:10<13:54,  7.59s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "69 34 failed to predict\n",
            "根据Alice的回答，她对爱情科幻作品持否定态度，认为人不能活在幻想里，这表明她在Fantasy维度上得分较低。她对于艺术和美的关注程度不明显，因此在Aesthetics维度上得分可能不高。她认为情感是生活中重要的一部分，这表明她在Feelings维度上得分较高。她喜欢尝试新事物，这表明她在Actions维度上得分较高。她喜欢思考和探索新的想法，这表明她在Ideas维度上得分较高。她对于传统的质疑和自由的信仰，这表明她在Values维度上得分较高。综合来看，被试Alice在大五人格中Openness的程度较高。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  40%|████      | 72/180 [08:32<16:56,  9.42s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "71 11 failed to predict\n",
            "根据Alice的回答，她表现出了一定的开放性，但并不是高度开放的人格。她在Fantasy维度上表现出了想象力，但是她的想象并不是积极的，而是消极的，表现出了一定的焦虑和悲观。在Aesthetics维度上，她并没有表现出对美的深刻关注。在Feelings维度上，她表现出了一定的情感强度，但是她的情感并不是积极的，而是消极的。在Actions维度上，她表现出了一定的开放性，但是她的态度并不是积极的，而是消极的。在Ideas维度上，她并没有表现出对思考的喜爱。在Values维度上，她的回答并没有表现出对自由和包容的态度。综合来看，被试Alice的开放性人格得分应该是中等偏低。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  42%|████▏     | 76/180 [09:07<16:47,  9.68s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "75 117 failed to predict\n",
            "根据Alice的回答，我们可以分析她在大五人格中的开放性程度：\n",
            "\n",
            "Fantasy：无法判断，因为没有相关回答。\n",
            "\n",
            "Aesthetics：无法判断，因为没有相关回答。\n",
            "\n",
            "Feelings：无法判断，因为没有相关回答。\n",
            "\n",
            "Actions：Alice提到了她在实习中需要坐地铁、搞卫生等，这表明她愿意尝试新的事物，因此可以判断她在Openness to Actions方面得分较高。\n",
            "\n",
            "Ideas：Alice提到了她想种向日葵，这表明她对新的想法和思考感兴趣，因此可以判断她在Openness to Ideas方面得分较高。\n",
            "\n",
            "Values：无法判断，因为没有相关回答。\n",
            "\n",
            "综上所述，根据Alice的回答，我们可以初步判断她在大五人格中的开放性程度较高，尤其是在Openness to Actions和Openness to Ideas方面。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "\rProcessing:  43%|████▎     | 77/180 [09:15<15:42,  9.15s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "76 129 failed to predict\n",
            "根据Alice的回答，她表现出了对于新事物的不太感兴趣，喜欢安静的生活，对于过去的生活和现在的生活没有什么区别，这些都表明她在Openness to Actions这个维度上得分可能不高。但是她对于教育和哲学上的思考表现出了一定的兴趣和深度，这可能表明她在Openness to Ideas这个维度上得分较高。因此，综合来看，被试Alice可能属于中等偏低的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  49%|████▉     | 88/180 [10:31<09:35,  6.26s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "87 23 failed to predict\n",
            "根据Alice的回答，她表现出了一定的开放性，比如她对于结婚的想法有一定的思考和反思，同时她也有一些固定的习惯，但她也表示即使替代品出现，她仍然会继续使用。综合来看，Alice可能属于中等程度的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  52%|█████▏    | 94/180 [11:14<11:16,  7.86s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "93 6 failed to predict\n",
            "根据Alice的回答，她提到了自己变得迟钝、不善于言辞、拖延等问题，这可能表明她在Openness to Actions这个维度上得分较低。但是她也提到了想清醒一点，不再沉迷于香烟、颓废和肮脏的生活，这可能表明她在Openness to Values这个维度上得分较高。她还提到了需要一个人来拯救自己，让自己不再孤独，这可能表明她在Openness to Feelings这个维度上得分较高。但是她提到的奇怪的名字和零点班并没有明确的解释，无法确定她在其他维度上的得分情况。综合来看，Alice可能是一个得分较高的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  53%|█████▎    | 96/180 [11:24<09:04,  6.48s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "95 17 failed to predict\n",
            "根据Alice的回答，我们可以看出她对于美学、情感、行动、思想和价值观等方面并没有明显的表现，也没有提到喜欢尝试新事物或者对于想象力的表现。因此，根据以上六个维度的解释，我们可以初步判断Alice的开放性人格较低。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  58%|█████▊    | 105/180 [12:36<10:00,  8.01s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "104 9 failed to predict\n",
            "根据Alice的回答，我们可以看出她对于中国网页游戏市场的情况有着详细的了解和分析，表现出了对于Ideas(Openness to Ideas)维度的高度开放性。但是在回答关于个人情感的问题时，她表现出了情感上的封闭和不愿意表露，这可能表明她在Feelings(Openness to Feelings)维度上的开放性较低。综合来看，Alice可能是一个中等程度的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  59%|█████▉    | 107/180 [12:46<08:01,  6.60s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "106 158 failed to predict\n",
            "根据Alice的回答，她对情感和价值观有着较强的关注和表达，但在想象力、审美、行动和思想方面并没有明显的表现。因此，可以判断Alice的开放性人格得分较低，尤其是在Fantasy、Aesthetics、Actions和Ideas这四个维度上得分较低。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "\rProcessing:  60%|██████    | 108/180 [12:54<08:30,  7.09s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "107 58 failed to predict\n",
            "根据Alice的回答，可以判断她在以下几个维度上的开放性程度：\n",
            "\n",
            "Fantasy：未提及\n",
            "Aesthetics：未提及\n",
            "Feelings：未提及\n",
            "Actions：未提及\n",
            "Ideas：高开放性，因为她喜欢看哲学论辩、谜题和面向受过教育的普通读者的非小说类书籍。\n",
            "Values：未提及\n",
            "\n",
            "综合来看，Alice在开放性方面的表现并不明显，因为她没有提到任何与开放性相关的话题。因此，无法确定她是高开放性还是低开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  62%|██████▏   | 111/180 [13:12<06:54,  6.00s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "110 171 failed to predict\n",
            "根据Alice的回答，她没有表现出高度的想象力、对美的关注、情感强度、尝试新事物的倾向、好奇心和对自由的信仰，因此可以判断她的开放性人格较低。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  66%|██████▌   | 118/180 [13:54<05:54,  5.73s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "117 16 failed to predict\n",
            "根据Alice的回答，她似乎不太符合高开放性人格的特征。她没有表现出对想象、美学、情感、行动、思想或价值观的强烈兴趣。相反，她似乎更注重自己的个人感受和满足，表现出一种相对封闭的态度。因此，我认为被试Alice属于低开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  71%|███████   | 127/180 [14:55<06:05,  6.90s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "126 8 failed to predict\n",
            "根据Alice的回答，她对于听到的令人啼笑皆非的事情并没有表现出强烈的情感反应，而是从思想和影响力的角度进行了分析。同时，她对于自己的生活状态感到索然无趣，希望改变现状。这表明她在Fantasy和Feelings维度上得分可能不是很高，但在Ideas和Actions维度上得分可能较高。因此，可以初步判断Alice属于中等偏高的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  93%|█████████▎| 167/180 [19:35<01:38,  7.60s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "166 98 failed to predict\n",
            "根据Alice的回答，她对于革命和反叛持有比较保守的态度，认为这只是一场无意义的表演，而且她也强调了人们应该注重精神生活和真正的需求。这表明她在Openness to Actions和Openness to Ideas这两个维度上可能不是很高，但是她也表达了对于精神生活和价值观的重视，这可能意味着她在Openness to Values这个维度上比较高。综合来看，被试Alice可能是一个中等程度的开放性人格。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing:  96%|█████████▌| 172/180 [20:07<00:56,  7.07s/it]"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "171 78 failed to predict\n",
            "根据Alice的回答，无法准确判断她的开放性人格水平。她的回答缺乏对于Fantasy、Aesthetics、Feelings、Actions、Ideas和Values六个维度的表现，也没有涉及到对于新事物、新思想、自由、美感等方面的态度和兴趣。因此，需要更多的信息和数据来评估她的开放性人格水平。\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing: 100%|██████████| 180/180 [21:07<00:00,  7.04s/it]\n"
          ]
        }
      ],
      "source": [
        "from tqdm import tqdm\n",
        "\n",
        "n = len(index_tuple)\n",
        "id_2_cates = [[] for _ in range(n)]\n",
        "\n",
        "for i in tqdm(range(n), desc='Processing'):\n",
        "    id = i\n",
        "    dialogs = [QAdata[f\"{index_tuple[id][0]}-low\"][index_tuple[id][1]]]\n",
        "    id = second_sample[i]\n",
        "    dialogs.append(QAdata[f\"{index_tuple[id][0]}-low\"][index_tuple[id][1]])\n",
        "\n",
        "    messages = evaluate_openness_message(dialogs)\n",
        "\n",
        "    return_msg = chat(messages)\n",
        "\n",
        "    response = return_msg.content\n",
        "    if '高开放' in response and '低开放' not in response:\n",
        "        id_2_cates[i].append('high')\n",
        "        id_2_cates[second_sample[i]].append('high')\n",
        "    elif '低开放' in response and '高开放' not in response:\n",
        "        id_2_cates[i].append('low')\n",
        "        id_2_cates[second_sample[i]].append('low')\n",
        "    else:\n",
        "        id_2_cates[i].append('neutral')\n",
        "        id_2_cates[second_sample[i]].append('neutral')\n",
        "        print(i, second_sample[i],'failed to predict')\n",
        "        print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 50,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rGyovjqk2RGZ",
        "outputId": "00fb0912-2495-4d3e-a1b9-d4377cf221e1"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "['neutral', 'low'] ('actions', 5)\n",
            "Q:「最近你的生活状态怎么样？」\n",
            "A:「最近的日子，我每天都是七、八点才起床，然后懒洋洋地躺在床上等到十点才起身吃午饭。午饭过后，我就继续拿着手机看电视，一直到晚上。晚上十一点多回家冲个凉，然后又躲回床上继续玩手机看电视，每天都是这样重复再重复。」\n",
            "['low', 'low'] ('aesthetics', 12)\n",
            "Q:「最近身边有个人让你感到很困扰，能不能跟我说说？」\n",
            "A:「是啊，我身边有个伪娘，整个人就像个女孩子一样，说话腻腻歪歪，做事拽拽的，走路还一步三摇。他对男人的事情一问三不知，对女人的事情却谈性勃发，假模假样的样子令人很反感。他甚至对美食都没了兴趣，只想和女人在一起。真是少见啊！」\n",
            "['low', 'low'] ('aesthetics', 24)\n",
            "Q:「最近你在家都在做什么呢？」\n",
            "A:「一般在家要么是玩xbox，要么看美剧。」\n",
            "Q:「今天怎么了？为什么想看电视？」\n",
            "A:「今天因为病了没精神，想看电视消磨时间。」\n",
            "Q:「看了电视有什么感想吗？」\n",
            "A:「真是不看不知道，一看吓一跳。怎么各个台都在做娱乐节目吗？怎么娱乐节目要么是东北话要么是港台腔了？怎么全都打美女牌，连我这个八零后都觉得低俗无聊难以忍受了！」\n",
            "Q:「你老公有什么看法吗？」\n",
            "A:「老公说广电总局估计是忙不过来了。」\n",
            "['neutral', 'low'] ('fantasy', 4)\n",
            "Q:「你觉得自己是一个单纯、简单、好的人吗？」\n",
            "A:「我觉得自己是一个单纯、简单、好的人。虽然有时候会受到挫折，但我依然相信人的本性是好的，所以我相信好人比坏人多。」\n",
            "Q:「你觉得这种单纯、简单、好的性格在现代社会发展中是否适应？」\n",
            "A:「这个嘛，可能有些不太适应吧。但是我觉得无论遇到什么困难和挫折，我都会坚持自己的信念，相信好人最终会有好报。」\n",
            "Q:「你说自己不适合玩狼人游戏，为什么呢？」\n",
            "A:「因为我实在不擅长扮演别人，我觉得自己还是比较真实和单纯的。」\n",
            "Q:「你的朋友说你的人生经历就像一本精彩的小说，你怎么看待这种评价？」\n",
            "A:「其实我并不追求过于惊险刺激的生活，我只是想要过平凡的生活。但是我也很感激自己经历过的一切，这些经历让我更加坚定了自己的信念和人生目标。」\n",
            "['low', 'neutral'] ('fantasy', 16)\n",
            "Q:「最近你有没有感觉到生活变得单调乏味了？」\n",
            "A:「是啊，我转了一圈，回到了原点，发现选了同样的一条路。现在的生活和过去的似乎没什么区别，我不爱玩，不爱疯，少了激情，只想安安静静。」\n",
            "Q:「你曾经有过什么激情吗？」\n",
            "A:「曾经有一些人闯入了我的生活，但最终发现他们都不适合我，也不懂我想要的安静。我犯了两次同样的错误，原来我一开始就在重复犯错。」\n",
            "['neutral', 'low'] ('fantasy', 29)\n",
            "Q:「最近你的生活规划有什么变化吗？」\n",
            "A:「我规划的生活是，远离你们，远离关于我点点滴滴的痕迹。我也不知道自己想去哪，只要能离开你们，去哪都无所谓了。」\n",
            "Q:「你为什么想要离开我们呢？」\n",
            "A:「我的束缚永远那么捆绑，我找不到出口点，我想不通的事一直是心头病。你们就是我的难题，我永远跨不过。只要不想起你们，我就能好起来。」\n",
            "['neutral', 'low'] ('feelings', 3)\n",
            "Q:「最近你感觉怎么样？有什么想法吗？」\n",
            "A:「我感觉自己变得迟钝了，不懂得如何表达，也不善于言辞，感觉和周围的人越来越陌生了。而且我总是拖延，什么事情都不想做。」\n",
            "Q:「你有没有想过改变自己的状态？」\n",
            "A:「我现在想清醒一点，不再沉迷于香烟、颓废和肮脏的生活。毕竟地球还是在自转运动，我不能一直这样下去。」\n",
            "Q:「你提到了一些奇怪的名字，这些是什么意思？」\n",
            "A:「哈哈哈，那些只是一些奇怪的名字，没有什么特别的含义。」\n",
            "Q:「你最后说到了等一个你爱的人，是什么意思？」\n",
            "A:「我只是觉得自己需要一个人来拯救我，让我不再像外星人一样孤独。」\n",
            "['neutral', 'low'] ('feelings', 9)\n",
            "Q:「开学以来，你有没有想过逃课？」\n",
            "A:「其实，从开学的第一天开始，我就一直想逃课。如果有朋友在，你们一定会陪我一起逃的，因为你们不会看到我痛苦。但是为了那全勤的学分，我每天都在麻木地上着一些我一点兴趣也没有的课，感觉很绝望，因为你们都不在。」\n",
            "['low', 'low'] ('ideas', 21)\n",
            "Q:「你对微博上流行的‘1、2、3、4～10～1×’这种内容有什么看法？」\n",
            "A:「我觉得这种内容虽然很流行，但是大部分人看过之后很快就会忘记。相比之下，如果是条理清晰的分析，只有3条、4条的内容，我们更容易理解和记忆。如果超过这个数，就会变得很困难。所以我对‘不三不四’这种所谓的‘哲言’一点兴趣也没有。」\"\"\"\n",
            "\n",
            "['low', 'low'] ('ideas', 22)\n",
            "Q:「你曾经是一名编剧，你觉得自己的知识结构是否足够支撑你的创作？」\n",
            "A:「其实我的知识结构非常单薄，就像一个无头的撑衣杆一样。我主要依赖于高中时学的文科知识，以及自己的人生经验和狭隘的兴趣。我不懂心理学、逻辑学、医学等等，如果编剧需要用到这些知识，我就会束手无策，不知道该怎么办。我的想象力也只能勉强支撑一些基于经验的情节，无法创造出更加奇妙的故事情节。这在中国影视编剧中也是很常见的问题。看了电影《盗梦空间》之后，我深有感触。」\n",
            "['low', 'low'] ('values', 25)\n",
            "Q:「你对新闻报道为什么总是正面新闻有什么看法？」\n",
            "A:「我觉得这是因为政府也不容易，他们需要维护国家的稳定，才能让国家更好的发展。而在微博这种地方，总会有一些人发表不满的言论，这也是难以避免的。」\n",
            "Q:「你认为国家的稳定和发展有什么关系吗？」\n",
            "A:「当然有关系了，只有国家稳定了，才能够更好的发展。」\n",
            "Q:「你有没有听说过一些人在各大论坛上混迹，职业的写手？」\n",
            "A:「是啊，我听说过一些人每天都在各大论坛上混迹，他们是职业的写手，总是发表一些不负责任的言论。这些人的心态也许需要放平稳一些。」\n",
            "Q:「你觉得我们与十年前相比，有没有进步呢？」\n",
            "A:「我觉得我们与十年前相比，确实有很大的进步。我们应该感谢政府和党，他们为国家的发展做出了很多贡献。」\n",
            "11\n"
          ]
        }
      ],
      "source": [
        "count = 0\n",
        "for cate, index  in zip( id_2_cates, index_tuple):\n",
        "    if cate[0] == 'low' and cate[1] == 'low':\n",
        "        print(cate, index)\n",
        "        print(QAdata[f\"{index[0]}-low\"][index[1]])\n",
        "        count += 1\n",
        "    if cate[0] == 'low' and cate[1] == 'neutral':\n",
        "        print(cate, index)\n",
        "        print(QAdata[f\"{index[0]}-low\"][index[1]])\n",
        "        count += 1\n",
        "    if cate[0] == 'neutral' and cate[1] == 'low':\n",
        "        print(cate, index)\n",
        "        print(QAdata[f\"{index[0]}-low\"][index[1]])\n",
        "        count += 1\n",
        "\n",
        "print( count )"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ls_smshWBV9F"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "colab": {
      "authorship_tag": "ABX9TyPV6cL/fvmnQlrVt4vtmvCR",
      "include_colab_link": true,
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
